import 'package:get/get.dart';
import 'package:sinosheets/route/route_paths.dart';

///加载webview的形式
enum SinoWebLoadType {
  html,
  url,
}

class AppRouter {
  static void backToHome() {
    Get.until((route) => Get.currentRoute == RoutePaths.initial);
  }

  static void back<T>([T? result]) {
    Get.back(result: result);
  }

  static Future<T?> toNamed<T>(
    String page, {
    dynamic arguments,
    int? id,
    bool preventDuplicates = true,
    Map<String, String>? parameters,
  }) async {
    return await Get.toNamed<T>(
      page,
      arguments: arguments,
      id: id,
      preventDuplicates: preventDuplicates,
      parameters: parameters,
    );
  }

  // WebView相关
  static Future<T?> toWebView<T>({
    required String url,
    String title = '',
    SinoWebLoadType type = SinoWebLoadType.url,
  }) {
    if (type == SinoWebLoadType.url) {
      return toNamed(
        RoutePaths.sinoWebView,
        arguments: {'url': url, 'title': title, 'type': type},
      );
    } else {
      return toNamed(
        RoutePaths.sinoWebView,
        arguments: {'html': url, 'title': title, 'type': type},
      );
    }
  }
}
